/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.db.DbMailbox;
/*     */ import com.zimbra.cs.db.DbPool;
/*     */ import com.zimbra.cs.db.DbPool.DbConnection;
/*     */ import com.zimbra.cs.mailbox.Mailbox.MailboxData;
/*     */ import com.zimbra.cs.session.AdminSession;
/*     */ import com.zimbra.cs.session.Session.Type;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetAllMailboxes
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   private static final String GET_ALL_MAILBOXES_CACHE_KEY = "GetAllMailboxes";
/*     */   public static final String SORT_TOTAL_USED = "totalUsed";
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  43 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*     */ 
/*  46 */     checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
/*     */     
/*  48 */     int limit = (int)request.getAttributeLong("limit", 2147483647L);
/*  49 */     if (limit == 0)
/*  50 */       limit = Integer.MAX_VALUE;
/*  51 */     int offset = (int)request.getAttributeLong("offset", 0L);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  61 */     MailboxesParams params = new MailboxesParams();
/*     */     
/*     */ 
/*  64 */     AdminSession session = (AdminSession)getSession(zsc, Session.Type.ADMIN);
/*  65 */     List<Mailbox.MailboxData> mailboxes; List<Mailbox.MailboxData> mailboxes; if (session != null) {
/*  66 */       MailboxesParams cachedParams = (MailboxesParams)session.getData("GetAllMailboxes");
/*  67 */       if ((cachedParams == null) || (!cachedParams.equals(params))) {
/*  68 */         List<Mailbox.MailboxData> mailboxes = params.doSearch();
/*  69 */         session.setData("GetAllMailboxes", params);
/*     */       } else {
/*  71 */         mailboxes = cachedParams.doSearch();
/*     */       }
/*     */     } else {
/*  74 */       mailboxes = params.doSearch();
/*     */     }
/*     */     
/*  77 */     Element response = zsc.createElement(AdminConstants.GET_ALL_MAILBOXES_RESPONSE);
/*  78 */     int limitMax = offset + limit;
/*  79 */     for (int i = offset; (i < limitMax) && (i < mailboxes.size()); i++) {
/*  80 */       Mailbox.MailboxData mailbox = (Mailbox.MailboxData)mailboxes.get(i);
/*     */       
/*  82 */       Element mbx = response.addElement("mbox");
/*  83 */       mbx.addAttribute("id", mailbox.id);
/*  84 */       mbx.addAttribute("groupId", mailbox.schemaGroupId);
/*  85 */       mbx.addAttribute("accountId", mailbox.accountId);
/*  86 */       mbx.addAttribute("indexVolumeId", mailbox.indexVolumeId);
/*  87 */       mbx.addAttribute("itemIdCheckPoint", mailbox.lastItemId);
/*  88 */       mbx.addAttribute("contactCount", mailbox.contacts);
/*  89 */       mbx.addAttribute("sizeCheckPoint", mailbox.size);
/*  90 */       mbx.addAttribute("changeCheckPoint", mailbox.lastChangeId);
/*  91 */       mbx.addAttribute("trackingSync", mailbox.trackSync);
/*  92 */       mbx.addAttribute("trackingImap", mailbox.trackImap);
/*  93 */       if (mailbox.lastBackupDate > 0) {
/*  94 */         mbx.addAttribute("lastbackupat", mailbox.lastBackupDate);
/*     */       }
/*  96 */       mbx.addAttribute("lastSoapAccess", mailbox.lastWriteDate);
/*  97 */       mbx.addAttribute("newMessages", mailbox.recentMessages);
/*     */     }
/*  99 */     response.addAttribute("more", i < mailboxes.size());
/* 100 */     response.addAttribute("searchTotal", mailboxes.size());
/* 101 */     return response;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   protected class MailboxesParams
/*     */   {
/*     */     String mSortBy;
/*     */     
/*     */ 
/*     */     boolean mSortAscending;
/*     */     
/*     */ 
/*     */     List<Mailbox.MailboxData> mResult;
/*     */     
/*     */ 
/*     */ 
/*     */     MailboxesParams() {}
/*     */     
/*     */ 
/*     */ 
/*     */     public boolean equals(Object o)
/*     */     {
/* 124 */       if (!(o instanceof MailboxesParams)) return false;
/* 125 */       if (o == this) { return true;
/*     */       }
/* 127 */       return true;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     List<Mailbox.MailboxData> doSearch()
/*     */       throws ServiceException
/*     */     {
/* 137 */       if (this.mResult != null) { return this.mResult;
/*     */       }
/* 139 */       List<Mailbox.MailboxData> result = null;
/* 140 */       DbPool.DbConnection conn = null;
/*     */       try {
/* 142 */         conn = DbPool.getConnection();
/* 143 */         result = DbMailbox.getMailboxRawData(conn);
/*     */       } finally {
/* 145 */         DbPool.quietClose(conn);
/*     */       }
/* 147 */       this.mResult = result;
/* 148 */       return this.mResult;
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 154 */     notes.add("Only system admins are allowed.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAllMailboxes.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */